package com.sk.restree.model.dao;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.ibatis.sqlmap.client.SqlMapClient;
import com.sk.restree.model.dto.BenefitDTO;
import com.sk.restree.model.ibatis.SqlMapFactory;

public class BenefitDAO {
	private static BenefitDAO instance;
	private SqlMapClient sqlMap;

	static {
		instance = new BenefitDAO();
	}

	private BenefitDAO() {
		sqlMap = SqlMapFactory.getSqlMapInstance();
	}

	public static BenefitDAO getInstance() {
		return instance;
	}

	@SuppressWarnings("unchecked")
	public List<BenefitDTO> getBenefitList(String card_id) {
		List<BenefitDTO> list = null;
		try {
			list = sqlMap.queryForList("selectBenefitList", card_id);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return list;
	}

	public List<BenefitDTO> getBenefitList(String card_id, String category) {
		List<BenefitDTO> list = null;
		Map<String,String> map = new HashMap<String, String>();
		map.put("card_id", card_id);
		map.put("category", category);
		try {
			list = sqlMap.queryForList("selectBenefitList2", map);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return list;
	}

	public BenefitDTO getBenefit(String card_id, String store_id) {
		BenefitDTO dto = null;
		Map<String,String> map = new HashMap<String, String>();
		map.put("card_id", card_id);
		map.put("store_id", store_id);
		try {
			dto = (BenefitDTO) sqlMap.queryForObject("selectBenefit", map);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return dto;
	}
}
